package com.zy.kotlinbaselibrary.base.activity

import android.os.Bundle
import android.widget.Toast
import com.zy.kotlinbaselibrary.base.mvp.BaseView
import com.zy.kotlinbaselibrary.base.mvp.IPresenter

@Suppress("UNCHECKED_CAST")
abstract class BasePresenterActivity<V: BaseView, P: IPresenter<V>>: BaseActivity(),  BaseView{

    val mPresenter: P by lazy { 
        createPresenter()
    }

    abstract fun createPresenter(): P


    override fun onCreate(savedInstanceState: Bundle?) {

        mPresenter.attachView(this as V)

        super.onCreate(savedInstanceState)
    }


    override fun onDestroy() {

        mPresenter.detachView()

        super.onDestroy()
    }

    override fun onRequestStart() {

    }

    override fun onRequestError(msg: String) {
        //        Toast.makeText(this, "网络异常", Toast.LENGTH_SHORT).show();
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
    }

    override fun onRequestEnd() {

    }

    override fun onInternetError() {

    }



}